/*
 * @Description: 全宗reducer
 * @Author: Rfan
 * @Date: 2022-01-08 16:30:05
 * @LastEditTime: 2022-05-25 13:51:25
 */

import { delItemByIdArray, editItemById, insertItem } from '@/utils/list';
import { ADD_TRANSFER, DELETE_TRANSFER, EDIT_TRANSFER, SET_TRANSFER_LIST } from '../constants';

export const TransferReducer = (state, action) => {
  switch (action.type) {
    // 设置移交清单列表
    case SET_TRANSFER_LIST:
      return {
        ...state,
        transferList: action.data
      };

    // 增加移交清单
    case ADD_TRANSFER:
      return {
        ...state,
        transferList: insertItem(action.data, state.transferList)
      };

    // 增加移交清单
    case EDIT_TRANSFER:
      return {
        ...state,
        transferList: editItemById(action.id, action.data, state.transferList)
      };

    // 删除移交清单
    case DELETE_TRANSFER:
      return {
        ...state,
        transferList: delItemByIdArray(action.ids, state.transferList)
      };

    default:
      console.log('untouched', action);
      return state;
  }
};
